package stack;

import java.util.ArrayList;
import java.util.Queue;
import java.util.Stack;

/**
 * @program: data_structures_algorithms
 * @description: 用栈模拟队列
 * @author: lld
 * @create: 2020-11-14 20:22
 **/
public class TwoStackToQueue {
    public static void main(String[] args) {
        TwoStackToQueue stackToQueue=new TwoStackToQueue();
        stackToQueue.add(1);
        stackToQueue.add(2);
        stackToQueue.add(3);
        System.out.println(stackToQueue.remove());
        System.out.println(stackToQueue.remove());
        stackToQueue.add(4);
        System.out.println(stackToQueue.remove());
        System.out.println(stackToQueue.remove());
    }
//    Queue queue= new Queue;
    private Stack<Integer> stack1=new Stack<>();
    private Stack<Integer> stack2=new Stack<>();
    //模拟入队
    public void add(int n){
        stack1.push(n);
    }
    //模拟出队
    public Integer remove(){
        while (!stack1.isEmpty()){
            stack2.push(stack1.pop());
        }
       return stack2.pop();
    }
}
